package com.battle.service.repository.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.battle.pojo.dto.role.UserRoleDto;
import com.battle.pojo.entity.LabelMp;
import com.battle.pojo.vo.label.GetLabelVo;
import com.battle.pojo.vo.labelMp.GetLabelMpDownListVo;
import com.battle.service.mapper.LabelMpMapper;
import com.battle.service.repository.in.LabelMpRepository;
import nirvana.core.repository.Repository;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service;
    import com.battle.pojo.dto.labelMp.*;
    import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.util.CollectionUtils;

/**
* 【描 述】：
* 【环 境】：J2SE
* 【详 细】：
*
*/
@Service
public class LabelMpRepositoryImpl extends Repository< LabelMpMapper , LabelMp> implements LabelMpRepository {

private final LabelMpMapper mapper;

public LabelMpRepositoryImpl(LabelMpMapper mapper) {
this.mapper = mapper;
}

    /**
    * 搜索标签关联表
    * @param dto
    * @return
    */
    @Override
    public Page< LabelMp > selectLabelMp(SelectLabelMpDto dto){

    return mapper.selectLabelMp(dto);
    }

@Override
public  Map<Long, LabelMp> getMap(List<Long> ids){
    Map<Long, LabelMp> map = new HashMap<>();

    if (CollectionUtil.isNotEmpty(ids)) {
        List<LabelMp> list =listByIds(ids);
        if (CollectionUtil.isNotEmpty(list)) {
        map = list.stream().collect(Collectors.toMap(LabelMp::getId, pojo -> pojo));
         }
        }
        return map;
    }

    @Override
    public Map<Long, List<GetLabelVo>> getListByFidIds(List<Long> fidIds) {
        if (CollectionUtils.isEmpty(fidIds)) {
            return Collections.EMPTY_MAP;
        }

        return mapper.getListByFidIds(fidIds)
                .stream()
                .collect(Collectors.groupingBy(GetLabelVo::getFid));

    }

    @Override
    public Map<Long, List<GetLabelVo>> getListByLabelIds(List<Long> labelIds) {
        if (CollectionUtils.isEmpty(labelIds)) {
            return Collections.EMPTY_MAP;
        }

        return mapper.getListByLabelIds(labelIds)
                .stream()
                .collect(Collectors.groupingBy(GetLabelVo::getLabelId));
    }

    @Override
    public List<GetLabelMpDownListVo> getDownList(List<String> textList) {
        return mapper.getDownList(textList);
    }


}